package com.geen.tuoke.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

/***
 * @author 86153
 * 不可滚动的viewpager
 */
public class NoScrollViewPager extends ViewPager {
    private boolean mNoFocus = true; //if true, keep View don't move

    public NoScrollViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoScrollViewPager(Context context) {
        this(context, null);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (mNoFocus) {
            return false;
        }
        return super.onInterceptTouchEvent(event);
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (mNoFocus) {
            return false;
        }
        return super.onTouchEvent(ev);
    }

    public void setNoFocus(boolean b) {
        mNoFocus = b;
    }
}